/**
 * Setvor project
 */
package setvor.yeild;

import java.util.Iterator;

/**
 * @author julatec
 *
 */
public class YeildIterable<T> implements Iterable<T> {

	protected Iterator<T> iterator;
	
	public YeildIterable(Iterator<T> iterator){
		if(iterator == null)
			throw new IllegalArgumentException("iterator cannot be null.");
		this.iterator = iterator;
	}
	
	@Override
	public Iterator<T> iterator() {
		return iterator;
	}
	
	public void filterBy(Filter<T> filter){
		if(filter == null)
			throw new IllegalArgumentException("filter cannot be null.");
		if(iterator instanceof FilterIterator<?>)
			((FilterIterator<T>)iterator).addFilter(filter);
		else
			iterator = new FilterIterator<T>(filter, iterator);
	}

}
